From 87a1e40eb8f386246d1cbe4a546f95e08b8f4463 Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Tue, 14 Oct 2003 20:09:39 +0000 Subject: [PATCH] New function to set the active row by iter. Tue Oct 14 16:10:21 2003 Jonathan Blandford * gtk/gtkcombobox.c (gtk_combo_box_set_active_iter): New function to set the active row by iter. * gtk/gtkcombobox.c (gtk_combo_box_get_active_iter): New function to get the active row by iter. --- ChangeLog | 8 +++++++ ChangeLog.pre-2-10 | 8 +++++++ ChangeLog.pre-2-4 | 8 +++++++ ChangeLog.pre-2-6 | 8 +++++++ ChangeLog.pre-2-8 | 8 +++++++ gtk/gtkcombobox.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ gtk/gtkcombobox.h | 4 ++++ 7 files changed, 103 insertions(+) diff --git a/ChangeLog b/ChangeLog index 97925d3971..45e3897b47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Oct 14 16:10:21 2003 Jonathan Blandford + + * gtk/gtkcombobox.c (gtk_combo_box_set_active_iter): New function + to set the active row by iter. + + * gtk/gtkcombobox.c (gtk_combo_box_get_active_iter): New function + to get the active row by iter. + 2003-10-13 Federico Mena Quintero * gtk/gtktreeview.c (gtk_tree_view_real_collapse_row): Don't do diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 97925d3971..45e3897b47 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Tue Oct 14 16:10:21 2003 Jonathan Blandford + + * gtk/gtkcombobox.c (gtk_combo_box_set_active_iter): New function + to set the active row by iter. + + * gtk/gtkcombobox.c (gtk_combo_box_get_active_iter): New function + to get the active row by iter. + 2003-10-13 Federico Mena Quintero * gtk/gtktreeview.c (gtk_tree_view_real_collapse_row): Don't do diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 97925d3971..45e3897b47 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +Tue Oct 14 16:10:21 2003 Jonathan Blandford + + * gtk/gtkcombobox.c (gtk_combo_box_set_active_iter): New function + to set the active row by iter. + + * gtk/gtkcombobox.c (gtk_combo_box_get_active_iter): New function + to get the active row by iter. + 2003-10-13 Federico Mena Quintero * gtk/gtktreeview.c (gtk_tree_view_real_collapse_row): Don't do diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 97925d3971..45e3897b47 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Tue Oct 14 16:10:21 2003 Jonathan Blandford + + * gtk/gtkcombobox.c (gtk_combo_box_set_active_iter): New function + to set the active row by iter. + + * gtk/gtkcombobox.c (gtk_combo_box_get_active_iter): New function + to get the active row by iter. + 2003-10-13 Federico Mena Quintero * gtk/gtktreeview.c (gtk_tree_view_real_collapse_row): Don't do diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 97925d3971..45e3897b47 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Tue Oct 14 16:10:21 2003 Jonathan Blandford + + * gtk/gtkcombobox.c (gtk_combo_box_set_active_iter): New function + to set the active row by iter. + + * gtk/gtkcombobox.c (gtk_combo_box_get_active_iter): New function + to get the active row by iter. + 2003-10-13 Federico Mena Quintero * gtk/gtktreeview.c (gtk_tree_view_real_collapse_row): Don't do diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index e685751e8b..3632786ae6 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -2392,6 +2392,65 @@ gtk_combo_box_set_active (GtkComboBox *combo_box, g_signal_emit_by_name (combo_box, "changed", NULL, NULL); } + +/** + * gtk_combo_box_get_active_iter: + * @combo_box: A #GtkComboBox + * @iter: The uninitialized #GtkTreeIter. + * + * Set @iter to point to the current active item, if it exists. + * + * Return value: %TRUE, if @iter was set + * + * Since: 2.4 + **/ +gboolean +gtk_combo_box_get_active_iter (GtkComboBox *combo_box, + GtkTreeIter *iter) +{ + GtkTreePath *path; + gint active; + gboolean retval; + + g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE); + + active = gtk_combo_box_get_active (combo_box); + if (active < 0) + return FALSE; + + path = gtk_tree_path_new_from_indices (active, -1); + retval = gtk_tree_model_get_iter (gtk_combo_box_get_model (combo_box), + iter, path); + gtk_tree_path_free (path); + + return retval; +} + +/** + * gtk_combo_box_set_active_iter: + * @combo_box: A #GtkComboBox + * @iter: The #GtkTreeIter. + * + * Sets the current active item to be the one referenced by @iter. + * + * Since: 2.4 + **/ +void +gtk_combo_box_set_active_iter (GtkComboBox *combo_box, + GtkTreeIter *iter) +{ + GtkTreePath *path; + + g_return_if_fail (GTK_IS_COMBO_BOX (combo_box)); + + path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter); + g_return_if_fail (path != NULL); + g_return_if_fail (gtk_tree_path_get_depth (path) != 1); + + gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]); + gtk_tree_path_free (path); +} + /** * gtk_combo_box_get_model * @combo_box: A #GtkComboBox. diff --git a/gtk/gtkcombobox.h b/gtk/gtkcombobox.h index bb9e0aa7c3..4a188a64af 100644 --- a/gtk/gtkcombobox.h +++ b/gtk/gtkcombobox.h @@ -70,6 +70,10 @@ void gtk_combo_box_set_column_span_column (GtkComboBox *combo_box, gint gtk_combo_box_get_active (GtkComboBox *combo_box); void gtk_combo_box_set_active (GtkComboBox *combo_box, gint index); +gboolean gtk_combo_box_get_active_iter (GtkComboBox *combo_box, + GtkTreeIter *iter); +void gtk_combo_box_set_active_iter (GtkComboBox *combo_box, + GtkTreeIter *iter); /* getters and setters */ GtkTreeModel *gtk_combo_box_get_model (GtkComboBox *combo_box); -- 2.30.2